<template>
  <view class="relayTheMessage" :style="DynamicHeight">
    <up-navbar title="扫码" :autoBack="false" placeholder @leftClick="leftClick"></up-navbar>
    <view :style="tabsDynamicHeight">

    </view>
  </view>
</template>

<script>
import jzH5ScanCode from '@/uni_modules/jz-h5-scanCode/js/index.js'
import {handleScanResult} from '@/utils/publicmethod'
export default {
  name: 'h5ScanUpload',
  components: {

  },
  data () {
    return {
      height: 0,
      DynamicHeight: {},
      tabsDynamicHeight: {},
    }
  },
  created () {
    this.height = (uni.getSystemInfoSync().windowHeight || uni.getSystemInfoSync().screenHeight) || 0
    this.DynamicHeight = {
      height: `${this.height}px`,
      overflow: 'hidden'
    }
    // #ifdef APP-PLUS
    this.tabsDynamicHeight = {
      height: `${this.height - 75}px`,
      overflow: 'hidden',
    }
    // #endif

    // #ifdef H5
    this.tabsDynamicHeight = {
      height: `${this.height - 45}px`,
      overflow: 'hidden',
    }
    // #endif
  },
  onLoad(){
      // #ifdef H5
      jzH5ScanCode.scanCode({
        success: (res) => {
          setTimeout(() => {
              jzH5ScanCode.destroy();
              handleScanResult(res.result);
          }, 300);
        },
        fail: (res) => {
          console.log('扫码失败:', res);
          uni.navigateBack()
        }
      })
      // #endif
  },
  onUnload(){
    console.log('销毁');
    // #ifdef H5
      setTimeout(() => {
        jzH5ScanCode.destroy();
      }, 300);
    // #endif
  },
  methods: {
    leftClick () {
      uni.navigateBack()
    },
  }

}
</script>

<style lang="scss" scoped>
.relayTheMessage {
  width: 100%;
  // background-color: #ffffff;

  .info-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 26rpx;
    padding: 0 15rpx 5rpx;
    gap: 10rpx;
    color: #8a8b8c;
  }
}
</style>